<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                  {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                               {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '../common/bus';
    export default {
        data() {
            if(window.location.host.indexOf('itnas.cn')>0){
                return {
                collapse: false,
                items: [
                    {
                        icon: 'el-icon-lx-home',
                        index: 'dashboard',
                        title: '首页'
                    },
                    {
                        icon: 'el-icon-s-tools',
                        index: '1',
                        title: '系统设置',
                        subs:[
                            {
                                index: 'project-manage',
                                title: '项目管理'
                            }, {
                                index: 'project-type',
                                title: '项目类型'
                            }, {
                                index: 'user-manage',
                                title: '用户管理'
                            }
                        ]
                    },{
                        icon: 'el-icon-menu',
                        index: '3',
                        title: '专业展',
                        subs:[
                            {
                                index: 'register_ui_manage',
                                title: '注册通道'
                            },  {
                                index: 'audience_manage',
                                title: '人员管理'
                            }, {
                                index: 'source_manage',
                                title: '来源管理'
                            }
                        ]
                    }
                ]
            }
        }else{
                return {
                collapse: false,
                items: [
                    {
                        icon: 'el-icon-lx-home',
                        index: 'dashboard',
                        title: '首页'
                    },
                    {
                        icon: 'el-icon-s-tools',
                        index: '1',
                        title: '系统设置',
                        subs:[
                            {
                                index: 'project-manage',
                                title: '项目管理'
                            }, {
                                index: 'project-type',
                                title: '项目类型'
                            }, {
                                index: 'user-manage',
                                title: '用户管理'
                            },{
                                index: 'auth-profile',
                                title: '角色权限配置'
                            },{
                                index: 'role-manage',
                                title: '用户项目角色'
                            },{
                                index: 'system-log',
                                title: '系统日志'
                            }
                        ]
                    },{
                        icon:'el-icon-user',
                        index:'2',
                        title:'证件/数据',
                        subs:[{
                                index: '2-3',
                                title: '证件管理',
                                subs:[
                                    {
                                        index: 'type-setting',
                                        title: '证件类型'
                                    }, {
                                        index: 'papers-record',
                                        title: '证件记录'
                                    }, 
                                    {
                                        index: 'distribute-document',
                                        title: '证件分发'
                                    }, 
                                    {
                                        index: 'record-document',
                                        title: '分发记录'
                                    },{
                                        index: 'head-manage',
                                        title: '头像管理'
                                    }
                                ]
                            }, {
                                index: '2-4',
                                title: '数据管理',
                                subs:[
                                    {
                                        index: 'access-control',
                                        title: '通行规则'
                                    }, {
                                        index: 'traffic-record',
                                        title: '证件通行记录'
                                    }, {
                                        index: 'ticket-record',
                                        title: '票通行记录'
                                    }, {
                                        index: 'statistics',
                                        title: '通行统计'
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-s-ticket',
                        index: '4',
                        title: '售票/赠票',
                        subs:[
                               { index: '4-0',
                                title: '票务管理',
                                subs:[
                                    {
                                        index: 'ticket-type-manage',
                                        title: '票种管理'
                                    },
                                    {
                                        index: 'import-ticket',
                                        title: '生成实体票'
                                    }, 
                                    {
                                        index: 'mobile-ticket',
                                        title: '生成电子票'
                                    }, 
                                    {
                                        index: 'ticket-all',
                                        title: '查询所有票'
                                    }]
                            }, 
                            {
                                index: '4-1',
                                title: '赠票管理',
                                subs:[
                                    {
                                        index: 'distribute-ticket',
                                        title: '赠票分发'
                                    }, {
                                        index: 'record-ticket',
                                        title: '赠票记录'
                                    }
                                ]
                            },  {
                                index: '4-2',
                                title: '购票管理',
                                subs:[
                                    {
                                        index: 'price-setting',
                                        title: '公众号设置'
                                    }, {
                                        index: 'record-manage',
                                        title: '购票记录'
                                    }
                                ]
                            }
                        ]
                    },{
                        icon: 'el-icon-menu',
                        index: '3',
                        title: '会议/展览',
                        subs:[
                            {
                                index: 'Exhibition',
                                title: '展商管理'
                            }, {
                                index: 'Exhibitors_exhibits',
                                title: '参展展品'
                            }, {
                                index: 'Register_ui_manage',
                                title: '注册通道'
                            },  {
                                index: 'Audience_manage',
                                title: '人员管理'
                            }, {
                                index: 'Source_manage',
                                title: '来源管理'
                            }, {
                                index: 'Contact',
                                title: '联系人'
                            }, {
                                index: 'invite',
                                title: '信息模板'
                            }, {
                                index: 'Contact_Invite',
                                title: '信息记录'
                            }
                        ]
                    }
                ]
            }
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
        }
    }
/*,{
        index: '3-2',
        title: '组委会',
        subs:[
            {
                index: 'vihicel_manage',
                title: '车辆管理'
            }, {
                index: 'content_publish',
                title: '内容发布'
            }, {
                index: '3-2-4',
                title: '数据看板'
            }
        ]
    }*/
</script>
<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 200px;
    }
    .sidebar > ul {
        height:100%;
    }
</style>
